import request from '@/utils/request';
// 导入我们将在模型层创建的类型
import type { ISetMeal, ISetMealPageResult, ISetMealPageQuery, ISetMealAddDTO, ISetMealEditDTO } from '@/types/setMeal';
import type { ICategory } from '@/types/category'; // 导入分类类型

/**
 *
 * 套餐管理
 *
 **/

// src/api/setMeal.ts
/**
 * 分页查询套餐
 * @param params - 查询参数
 */
export const getSetMealPage = (params: ISetMealPageQuery) => {
  return request<ISetMealPageResult>({
    url: '/setmeal/page',
    method: 'get',
    params
  });
};

/**
 * 新增套餐
 * @param data - 套餐数据
 */
export const addSetMeal = (data: ISetMealAddDTO) => {
  return request({
    url: '/setmeal',
    method: 'post',
    data
  });
};

/**
 * 修改套餐
 * @param data - 套餐数据
 */
export const editSetMeal = (data: ISetMealEditDTO) => {
  return request({
    url: '/setmeal',
    method: 'put',
    data
  });
};

/**
 * 根据id查询套餐
 * @param id - 套餐id
 */
export const getSetMealById = (id: number) => {
  return request<ISetMeal>({
    url: `/setmeal/${id}`,
    method: 'get'
  });
};

/**
 * 批量删除套餐
 * @param ids - 套餐id字符串，以逗号分隔
 */
export const deleteSetMeal = (ids: string) => {
  return request({
    url: '/setmeal',
    method: 'delete',
    params: { ids }
  });
};

/**
 * 套餐起售、停售
 * @param params - 包含 status 和 id
 */
export const updateSetMealStatus = (params: { status: 0 | 1; id: number }) => {
  return request({
    url: `/setmeal/status/${params.status}`,
    method: 'post',
    params: { id: params.id }
  });
};

/**
 * (复用) 根据类型查询分类 - 用于套餐分类下拉列表
 * @param params - { type: 2 }
 */
export const getCategoryListForSetMeal = (params: { type: number }) => {
  return request<ICategory[]>({
    url: `/category/list`,
    method: 'get',
    params
  });
};
